clear all
set maxvar 10000

** DEFINE PATH HERE
global main_path " "


cd "$main_path"
use "$main_path\Phaseout_all_surveyrounds.dta", clear

set more off



*** NOTE: seasons are numbered starting from pre-phaseout baseline: 
*** s1 is the pre-phaseout baseline season (occured 2 seasons prior to phaseout). s3,s5,s7 and s8 correspond to 1,3,5 and 6 seasons post phaseout, as they are referred to in the paper.
	
	
*** Table I: Balance table, experimental groups - baseline ***
eststo clear
eststo continuation: quietly estpost summarize   impseed_s1 brac_alt_s1 market_alt_s1 orgfert_s1  if treatment==1
eststo phaseout_all: quietly estpost summarize   impseed_s1 brac_alt_s1 market_alt_s1 orgfert_s1  if treatment==2 | treatment==3
eststo cap_phaseout: quietly estpost summarize   impseed_s1 brac_alt_s1 market_alt_s1 orgfert_s1 if treatment==2
eststo mf_phaseout: quietly estpost summarize   impseed_s1 brac_alt_s1 market_alt_s1 orgfert_s1 if treatment==3
eststo diff12: quietly estpost ttest   impseed_s1 brac_alt_s1 market_alt_s1 orgfert_s1 if treatment>0, by(phaseout) unequal
eststo diff1: quietly estpost ttest  impseed_s1 brac_alt_s1 market_alt_s1 orgfert_s1 if treatment==1 | treatment==2, by(treatment) unequal
eststo diff2: quietly estpost ttest  impseed_s1 brac_alt_s1 market_alt_s1 orgfert_s1 if treatment==1 | treatment==3, by(treatment) unequal
esttab  continuation phaseout_all cap_phaseout mf_phaseout diff12 diff1 diff2 using balance_table1.csv, cells("mean(pattern(1 1 1 1 0 0 0) fmt(3)) sd(pattern(1 1 1 1 0 0 0)) b(star pattern(0 0 0 0 1 1 1) fmt(3)) t(pattern(0 0 0 0 1 1 1) par fmt(3))") star(* 0.10 ** 0.05 *** 0.01) label replace

eststo clear
eststo continuation: quietly estpost summarize  croprotation_s1 intercrop_s1 linesow_s1 weed_s1 zerotill_s1 pest_s1  if treatment==1
eststo phaseout_all: quietly estpost summarize  croprotation_s1 intercrop_s1 linesow_s1 weed_s1 zerotill_s1 pest_s1 if treatment==2 | treatment==3
eststo cap_phaseout: quietly estpost summarize  croprotation_s1 intercrop_s1 linesow_s1 weed_s1 zerotill_s1 pest_s1 if treatment==2
eststo mf_phaseout: quietly estpost summarize   croprotation_s1 intercrop_s1 linesow_s1 weed_s1 zerotill_s1 pest_s1 if treatment==3
eststo diff12: quietly estpost ttest   croprotation_s1 intercrop_s1 linesow_s1 weed_s1 zerotill_s1 pest_s1 if treatment>0, by(phaseout) unequal
eststo diff1: quietly estpost ttest  croprotation_s1 intercrop_s1 linesow_s1 weed_s1 zerotill_s1 pest_s1 if treatment==1 | treatment==2, by(treatment) unequal
eststo diff2: quietly estpost ttest  croprotation_s1 intercrop_s1 linesow_s1 weed_s1 zerotill_s1 pest_s1 if treatment==1 | treatment==3, by(treatment) unequal
esttab  continuation phaseout_all cap_phaseout mf_phaseout diff12 diff1 diff2 using balance_table2.csv, cells("mean(pattern(1 1 1 1 0 0 0) fmt(3)) sd(pattern(1 1 1 1 0 0 0)) b(star pattern(0 0 0 0 1 1 1) fmt(3)) t(pattern(0 0 0 0 1 1 1) par fmt(3))") star(* 0.10 ** 0.05 *** 0.01) label replace

eststo clear
eststo continuation: quietly estpost summarize   age_member1_s1 cultivated_land_s1 cultivate_ownland_s1 title_s1 rooms_mainhouse_s1 clothes_s1 shoes_s1 mobile_amt_s1 hhappliances_amt_s1 poultry_amt_s1 livestock_small_amt_s1 livestock_large_amt_s1  if treatment==1
eststo phaseout_all: quietly estpost summarize   age_member1_s1 cultivated_land_s1 cultivate_ownland_s1 title_s1 rooms_mainhouse_s1 clothes_s1 shoes_s1 mobile_amt_s1 hhappliances_amt_s1 poultry_amt_s1 livestock_small_amt_s1 livestock_large_amt_s1  if treatment==2 | treatment==3
eststo cap_phaseout: quietly estpost summarize   age_member1_s1 cultivated_land_s1 cultivate_ownland_s1 title_s1 rooms_mainhouse_s1 clothes_s1 shoes_s1 mobile_amt_s1 hhappliances_amt_s1 poultry_amt_s1 livestock_small_amt_s1 livestock_large_amt_s1  if treatment==2
eststo mf_phaseout: quietly estpost summarize   age_member1_s1 cultivated_land_s1 cultivate_ownland_s1 title_s1 rooms_mainhouse_s1 clothes_s1 shoes_s1 mobile_amt_s1 hhappliances_amt_s1 poultry_amt_s1 livestock_small_amt_s1 livestock_large_amt_s1  if treatment==3
eststo diff12: quietly estpost ttest   age_member1_s1 cultivated_land_s1 cultivate_ownland_s1 title_s1 rooms_mainhouse_s1 clothes_s1 shoes_s1 mobile_amt_s1 hhappliances_amt_s1 poultry_amt_s1 livestock_small_amt_s1 livestock_large_amt_s1  if treatment>0, by(phaseout) unequal
eststo diff1: quietly estpost ttest  age_member1_s1 cultivated_land_s1 cultivate_ownland_s1 title_s1 rooms_mainhouse_s1 clothes_s1 shoes_s1 mobile_amt_s1 hhappliances_amt_s1 poultry_amt_s1 livestock_small_amt_s1 livestock_large_amt_s1  if treatment==1 | treatment==2, by(treatment) unequal
eststo diff2: quietly estpost ttest  age_member1_s1 cultivated_land_s1 cultivate_ownland_s1 title_s1 rooms_mainhouse_s1 clothes_s1 shoes_s1 mobile_amt_s1 hhappliances_amt_s1 poultry_amt_s1 livestock_small_amt_s1 livestock_large_amt_s1  if treatment==1 | treatment==3, by(treatment) unequal
esttab  continuation phaseout_all cap_phaseout mf_phaseout diff12 diff1 diff2 using balance_table3.csv, cells("mean(pattern(1 1 1 1 0 0 0) fmt(3)) sd(pattern(1 1 1 1 0 0 0)) b(star pattern(0 0 0 0 1 1 1) fmt(3)) t(pattern(0 0 0 0 1 1 1) par fmt(3))") star(* 0.10 ** 0.05 *** 0.01) label replace




	
	
*** Phaseout effects ***
 ** main results **
 
* Table II: Phaseout effect on improved seed use  
eststo clear
foreach var in impseed_s3 impseed_s5 impseed_s7 impseed_s8 {
eststo: areg `var' phaseout impseed_s1 weed_s1 linesow_s1 orgfert_s1 title_s1,absorb(bcode) cluster(ccode)
}
esttab _all using phaseout_tableIIa.csv, cells(b(fmt(3) star) ci(fmt(3)par)) drop(_cons) r2(2) star(* 0.10 ** 0.05 *** 0.01) noobs label  plain  replace

* Table II: Phaseout effect on improved seed quantities  
eststo clear
foreach var in  impseed_quantity_peracre_s5 impseed_quantity_peracre_s7 {
eststo: areg `var' phaseout  weed_s1 orgfert_s1 linesow_s1 title_s1, absorb(bcode) cluster(ccode)
}
esttab _all using phaseout_tableIIb.csv, cells(b(fmt(3) star) ci(fmt(3)par)) drop(_cons) r2(2) star(* 0.10 ** 0.05 *** 0.01) noobs label  plain  replace

* Table II: Phaseout effect on local seed use  
eststo clear
foreach var in localseed_s3 localseed_s5 localseed_s7 localseed_s8 {
eststo: areg `var' phaseout localseed_s1 weed_s1 linesow_s1 orgfert_s1 title_s1,absorb(bcode) cluster(ccode)
}
esttab _all using phaseout_tableIIc.csv, cells(b(fmt(3) star) ci(fmt(3)par)) drop(_cons) r2(2) star(* 0.10 ** 0.05 *** 0.01) noobs label  plain  replace

* Table II: Phaseout effect on local seed quantities   
eststo clear
foreach var in   localseed_quantity_peracre_s5 localseed_quantity_peracre_s7 {
eststo: areg `var' phaseout  weed_s1 orgfert_s1 linesow_s1 title_s1, absorb(bcode) cluster(ccode)
}
esttab _all using phaseout_tableIId.csv, cells(b(fmt(3) star) ci(fmt(3)par)) drop(_cons) r2(2) star(* 0.10 ** 0.05 *** 0.01) noobs label  plain  replace




* Table III: Phaseout effect on improved seed use by source  
eststo clear
foreach num in 3 5 7 8 {
foreach var in  brac_alt_s market_alt_s otherbrac_alt_s{
eststo: areg `var'`num' phaseout `var'1 weed_s1 linesow_s1 orgfert_s1 title_s1,absorb(bcode) cluster(ccode)
}
}
esttab _all using phaseout_tableIII.csv, cells(b(fmt(3) star) se(fmt(3)par)) drop(_cons) r2(2) star(* 0.10 ** 0.05 *** 0.01) noobs label    replace



* Table IV :Phaseout effect on practices - 
eststo clear 
foreach num in 5 8 {
foreach var in croprotation_s intercrop_s linesow_s  orgfert_s chemfert_s weed_s  pest_s {
eststo: areg `var'`num' phaseout `var'1 weed_s1 linesow_s1 orgfert_s1 title_s1,absorb(bcode) cluster(ccode)
}
}
esttab _all using phaseout_tableIV.csv, cells(b(fmt(3) star) ci(fmt(3)par)) drop(_cons) r2(2) star(* 0.10 ** 0.05 *** 0.01) noobs label  plain  replace



*Note: code that reproduces the appendix results is commented out below
/* 


 ** Additional results, Appendix A **
 
* Table AIII: Phaseout effect on other inputs and tools -  
eststo clear
foreach num in 5 8 {
foreach var in hiredlabor_s pesticide_s handplow_s mechplow_s   {
eststo: areg `var'`num' phaseout `var'1 weed_s1 linesow_s1 orgfert_s1 title_s1,absorb(bcode) cluster(ccode)
}
}
esttab _all using phaseout_tableAIII.csv, cells(b(fmt(3) star) ci(fmt(3)par)) drop(_cons) r2(2) star(* 0.10 ** 0.05 *** 0.01) noobs label  plain  replace

*note: data on use of pump for pesticide was not gathered at baseline so can't control for it
areg use_pestpump_s5 phaseout  weed_s1 linesow_s1 orgfert_s1 title_s1,absorb(bcode) cluster(ccode)
areg use_pestpump_s8 phaseout  weed_s1 linesow_s1 orgfert_s1 title_s1,absorb(bcode) cluster(ccode)



* Table AIV: Phaseout effect on crop diversification -  
eststo clear
foreach num in 3 5 7 {
foreach var in cropno_s grow_maize_s {
eststo: areg `var'`num' phaseout `var'1 weed_s1 linesow_s1 orgfert_s1 title_s1,absorb(bcode) cluster(ccode)
}
}
esttab _all using phaseout_tableAIV.csv, cells(b(fmt(3) star) ci(fmt(3)par)) drop(_cons) r2(2) star(* 0.10 ** 0.05 *** 0.01) noobs label  plain  replace



* Table AVIII: Farmers views on CAP/MF activity
*recoding categorical into dummy vars
foreach var in cap_seedqual cap_higheryield cap_higherprofit mf_newcult mf_bettercult mf_higheryield mf_higherprofit {
gen `var'_dummy_s8 = `var'_s8
recode `var'_dummy_s8  2=1 3/5=0
gen `var'_dummy_s5 = `var'_s5
recode `var'_dummy_s5  2=1 3/5=0
}

eststo clear
eststo cont: estpost sum cap_seedqual_dummy_s8 cap_higheryield_dummy_s8 cap_higherprofit_dummy_s8 mf_newcult_dummy_s8 mf_bettercult_dummy_s8 mf_higheryield_dummy_s8 mf_higherprofit_dummy_s8 if treatment==1
eststo mf: estpost sum cap_seedqual_dummy_s8 cap_higheryield_dummy_s8 cap_higherprofit_dummy_s8 mf_newcult_dummy_s8 mf_bettercult_dummy_s8 mf_higheryield_dummy_s8 mf_higherprofit_dummy_s8 if treatment==2
eststo cap: estpost sum cap_seedqual_dummy_s8 cap_higheryield_dummy_s8 cap_higherprofit_dummy_s8 mf_newcult_dummy_s8 mf_bettercult_dummy_s8 mf_higheryield_dummy_s8 mf_higherprofit_dummy_s8 if treatment==3
esttab cont mf cap using phaseout_tableAVIII.csv, cells(mean(fmt(3)) sd(par fmt(3))) replace 






*** Appendix B
* The code follows the main results, except that both treatment arms are separately specified.

* Phaseout effect on improved seed use - separately by treatment branch
eststo clear
foreach var in impseed_s3 impseed_s5 impseed_s7 impseed_s8 {
eststo: areg `var' i.treatment impseed_s1 weed_s1 linesow_s1 orgfert_s1 title_s1 if phaseout!=.,absorb(bcode) cluster(ccode)
}
esttab _all using phaseout_tableBI.csv, cells(b(fmt(3) star) ci(fmt(3)par)) drop(_cons) r2(2) star(* 0.10 ** 0.05 *** 0.01) noobs label  plain  replace

eststo clear
foreach var in impseed_quantity_s5 impseed_quantity_s7 impseed_quantity_peracre_s5 impseed_quantity_peracre_s7 {
eststo: areg `var' i.treatment impseed_s1 weed_s1 linesow_s1 orgfert_s1 title_s1 if phaseout!=.,absorb(bcode) cluster(ccode)
}
esttab _all using phaseout_tableBII.csv, cells(b(fmt(3) star) ci(fmt(3)par)) drop(_cons) r2(2) star(* 0.10 ** 0.05 *** 0.01) noobs label  plain  replace



* Phaseout effect on local seed use - separately by treatment branch
eststo clear
foreach var in localseed_s3 localseed_s5 localseed_s7 localseed_s8 {
eststo: areg `var' i.treatment localseed_s1 weed_s1 linesow_s1 orgfert_s1 title_s1 if phaseout!=.,absorb(bcode) cluster(ccode)
}
esttab _all using phaseout_tableBIII.csv, cells(b(fmt(3) star) ci(fmt(3)par)) drop(_cons) r2(2) star(* 0.10 ** 0.05 *** 0.01) noobs label  plain  replace

eststo clear
foreach var in  localseed_quantity_s5 localseed_quantity_s7 localseed_quantity_peracre_s5 localseed_quantity_peracre_s7 {
eststo: areg `var' i.treatment localseed_s1 weed_s1 linesow_s1 orgfert_s1 title_s1 if phaseout!=.,absorb(bcode) cluster(ccode)
}
esttab _all using phaseout_tableBIV.csv, cells(b(fmt(3) star) ci(fmt(3)par)) drop(_cons) r2(2) star(* 0.10 ** 0.05 *** 0.01) noobs label  plain  replace



* Phaseout effect on improved seed use by source of seed - separately by treatment arm
eststo clear
foreach num in 3 5 7 8 {
foreach var in market_alt_s brac_alt_s otherbrac_alt_s{
eststo: areg `var'`num' i.treatment `var'1  weed_s1 linesow_s1 orgfert_s1 title_s1 if phaseout!=.,absorb(bcode) cluster(ccode)
}
}
esttab _all using phaseout_tableBV.csv, cells(b(fmt(3) star) se(fmt(3)par)) drop(_cons) r2(2) star(* 0.10 ** 0.05 *** 0.01) noobs label    replace







*** Table AVII: ***

clear
use "C:\Users\vidab\OneDrive - Inter-American Development Bank Group\docs\gw\CAP_s5_s8.dta", replace

eststo clear
foreach var in sold_brac_maize_s5 log_maize_brac_sold_s5 log_maize_brac_price_s5 sold_brac_maize_s8 log_maize_brac_sold_s8 log_maize_brac_price_s8 {
eststo: areg `var' phaseout, absorb(bcode) cluster(ccode)
}
esttab _all using phaseout_tableAVII.csv, cells(b(fmt(3) star) se(fmt(3)par)) drop(_cons) r2(2) star(* 0.10 ** 0.05 *** 0.01) noobs label   replace



